<template>
  <div class="app-container">
    <div class="income" style="margin: 10px; text-align: center">
      <el-row :gutter="20" justify="center" type="flex">
        <el-col :span="6"
          ><div class="grid-content bg-purple">
            <span>今日收入：</span>{{ income.todayIncome }}
          </div></el-col
        >
        <el-col :span="6"
          ><div class="grid-content bg-purple"></div>
          <span>本周收入：</span>{{ income.weekIncome }}</el-col
        >
        <el-col :span="6"
          ><div class="grid-content bg-purple"></div>
          <span>本月收入：</span>{{ income.monthlyIncome }}</el-col
        >
        <el-col :span="6"
          ><div class="grid-content bg-purple"></div>
          <span>本年收入：</span>{{ income.yearIncome }}</el-col
        >
      </el-row>
    </div>
    <div class="filter-container">
      <span>订单编号：</span>
      <el-input
        v-model="paramOrder.orderSn"
        placeholder="请输入订单编号"
        style="width: 200px"
        class="filter-item"
      />
      <span class="leftMar">用户名：</span>
      <el-input
        v-model="paramOrder.nickname"
        placeholder="请输入用户名"
        style="width: 200px"
        class="filter-item"
      />
      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="search"
      >
        搜索
      </el-button>
    </div>
    <el-table
      :data="dataList"
      v-loading="listLoading"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column label="序号" width="80" align="center">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="日期" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.orderCompletionTime }}</span>
        </template>
      </el-table-column>
      <!--   <el-table-column label="账号" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.paymentTime }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="用户名" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.nickname }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单编号" width="200" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.orderSn }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单总额" width="100" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.totalAmount }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提成金额(元)" width="250" align="center">
        <template slot-scope="{ row }">
          <span>{{ row.commissionAmount }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <!--  <el-button size="mini">查看</el-button> -->
          <el-button size="mini" type="danger" @click="deleteFinance(row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :page-size="10"
      :total="total_size"
      @current-change="changePage"
    >
    </el-pagination>
  </div>
</template>

<script>
import { GetFinance, GetFindIncome, DeleteFinance } from "@/api/finance";
export default {
  name: "indent",
  data() {
    return {
      total_size: 0, //多少条数据
      paramOrder: {
        //订单查询条件
        currPage: 1,
        pageSize: 10,
        orderSn: "",
        addressee: "",
        status: "",
        time: ["", ""],
      },
      value1: "",
      listLoading: true, //加载
      dataList: [], //数据
      income: {
        monthlyIncome: 0,
        todayIncome: 0,
        weekIncome: 0,
        yearIncome: 0,
      }, //收入
    };
  },
  created() {
    this.getFinance();
    this.getFindIncome();
  },
  methods: {
    search() {
      this.getFinance();
    },
    changePage(page) {
      console.log(page);
      this.paramOrder.currPage = page;
      this.getOrderList();
    },
    //获取财务列表
    getFinance() {
      GetFinance(this.paramOrder).then((res) => {
        this.dataList = res.data.data_list;
        this.total_size = res.data.total_size;
        this.listLoading = false;
      });
    },
    //收入查询
    getFindIncome() {
      GetFindIncome().then((res) => {
        console.log(res);
        if (res.data) {
          this.income = res.data;
        }
      });
    },
    //删除记录
    deleteFinance(id) {
      DeleteFinance(id).then((res) => {
        if (res.code == 200) {
          this.$message.success("删除成功");
          this.getFinance();
          this.getFindIncome();
        } else {
          this.$message.error("删除失败");
        }
      });
    },
  },
};
</script>
<style scoped>
.leftMar {
  margin-left: 8px;
}
.filter-container {
  margin-bottom: 10px;
}
</style>